1 <?php
2
3 session_start();
4 require "includes/db.php";
5 require "includes/functions.php";
6
7 if(!isset($_SESSION['user'])) {
8 header("location: logout.php");
9 }
10
11 $msg = "";
12
13 if($_SERVER['REQUEST_METHOD'] == 'POST') {
14
15 if(isset($_POST['submit']) && isset($_FILES['file'])) {
16
17 $cat = htmlentities($_POST['category'], ENT_QUOTES, 'UTF-8');
18 $name = htmlentities($_POST['name'], ENT_QUOTES, 'UTF-8');
19 $price = htmlentities($_POST['price'], ENT_QUOTES, 'UTF-8');
20 $desc = htmlentities($_POST['desc'], ENT_QUOTES, 'UTF-8');
21 $file = $_FILES['file'];
22 $allowed_ext = array("jpg", "jpeg", "JPG", "JPEG", "png", "PNG");
23
24 if($cat != "" && $name != "" && $price != "" && $desc != "" && empty($file) == false) {
25
26 $ext = explode(".", $_FILES['file']['name']);
27
28 if(in_array($ext[1], $allowed_ext)) {
29
30 $check = $db->query("SELECT * FROM food WHERE food_name='".$name."' LIMIT 1");
31
32 if($check->num_rows) {
33
34 $msg = "<p style='color:red; padding: 10px; background: #ffeeee;'>No duplicate food name allowed. Try again!!!</p>";
35
36 }else{
37
38 $insert = $db->query("INSERT INTO food(food_name, food_category, food_price, food_description) VALUES('".$name."', '".$cat."', '".$price."', '".$desc."')");
39
40 if($insert) {
41
42 $ins_id = $db->insert_id;
43
44 $image_url = "../image/FoodPics/$ins_id.jpg";
45
46 if(move_uploaded_file($_FILES['file']['tmp_name'], $image_url)) {
47
48 $msg = "<p style='color:green; padding: 10px; background: #eeffee;'>Lưu thành công</p>";
49
50 }else{
51
52 $msg = "<p style='color:red; padding: 10px; background: #ffeeee;'>Không thành công, xin thử lại</p>";
53
54 }
55
56 }
57
58 }
59
60 }else{
61
62 $msg = "<p style='color:red; padding: 10px; background: #ffeeee;'>Invalid image file format</p>";
63
64 }
65
66 }else{
67
68 $msg = "<p style='color:red; padding: 10px; background: #ffeeee;'>Incomplete form data</p>";
69
70 }
71
72 }
73
74 }
75
76 ?>
77
78 <!doctype html>
79 <html lang="en">
80 <head>
81 <meta charset="utf-8" />
82 <link rel="icon" type="image/png" href="assets/img/favicon.ico">
83 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
84
85 <title>Trà Sữa Milk Tea Hương Vị Thơm - Chuẩn Vị Ngon</title>
86
87 <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
88 <meta name="viewport" content="width=device-width" />
89
90
91 <!-- Bootstrap core CSS -->
92 <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
93
94 <!-- Animation library for notifications -->
95 <link href="assets/css/animate.min.css" rel="stylesheet"/>
96
97 <!-- Light Bootstrap Table core CSS -->
98 <link href="assets/css/light-bootstrap-dashboard.css" rel="stylesheet"/>
99
100
101 <!-- CSS for Demo Purpose, don't include it in your project -->
102 <link href="assets/css/demo.css" rel="stylesheet" />
103
104
105 <!-- Fonts and icons -->
106 <link href="assets/css/pe-icon-7-stroke.css" rel="stylesheet" />
107
108 <link href="assets/css/style.css" rel="stylesheet" />
109
110 </head>
111 <body>
112
113 <div class="wrapper">
114 <div class="sidebar" data-color="#000" data-image="assets/img/sidebar-5.jpg">
115
116 <!-- you can change the color of the sidebar using: data-color="blue | azure | green | orange | red | purple" -->
117
118
119 <?php require "includes/side_wrapper.php"; ?>
120
121 <div class="main-panel">
122 <nav class="navbar navbar-default navbar-fixed" style="background: #FF5722;">
123 <div class="container-fluid">
124 <div class="navbar-header">
125 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigation-example-2">
126 <span class="sr-only">Toggle navigation</span>
127 <span class="icon-bar" style="background: #fff;"></span>
128 <span class="icon-bar" style="background: #fff;"></span>
129 <span class="icon-bar" style="background: #fff;"></span>
130 </button>
131 <a class="navbar-brand" href="#" style="color: #fff;">Thêm mới thực đơn</a>
132 </div>
133 <div class="collapse navbar-collapse">
134
135 <ul class="nav navbar-nav navbar-right">
136 <li>
137 <a href="logout.php" style="color: #fff;">
138 Thoát
139 </a>
140 </li>
141 </ul>
142 </div>
143 </div>
144 </nav>
145
146
147 <div class="content">
148 <div class="container-fluid">
149 <div class="row">
150 <div class="col-md-8">
151 <div class="card">
152 <div class="header">
153 <h4 class="title">Thêm thực đơn</h4>
154 </div>
155 <div class="content">
156 <form method="post" action="food_add.php" enctype="multipart/form-data">
157 <div class="row">
158 <div class="col-md-12">
159
160 <?php echo $msg; ?>
161
162 <div class="form-group">
163 <label style="color: #333">Danh mục</label>
164 <select name="category" class="form-control" required />
165 <option value="">Chọn danh mục trà sữa</option>
166 <option value="breakfast">Trà sữa trân châu trắng</option>
167 <option value="lunch">Trà sữa Oreo Cake Cream</option>
168 <option value="dinner">Trà xoài kem cheese</option>
169 <option value="special">Trà sữa khoai môn</option>
170 <option value="suongsao">Trà sữa sương sáo</option>
171 </select>
172 </div>
173 </div>
174 </div>
175
176 <div class="row">
177 <div class="col-md-12">
178 <div class="form-group">
179 <label style="color: #333">Tên món</label>
180 <input type="text" autofocus name="name" class="form-control" placeholder="Tên sản phẩm" required />
181 </div>
182 </div>
183 </div>
184
185 <div class="row">
186 <div class="col-md-12">
187 <div class="form-group">
188 <label style="color: #333" for="price">Giá</label>
189 <input type="text" name="price" id="price" class="form-control" placeholder="Giá sản phẩm" required />
190 </div>
191 </div>
192 </div>
193
194 <div class="row">
195 <div class="col-md-12">
196 <div class="form-group">
197 <label style="color: #333" for="txtarea">Mô tả</label>
198 <textarea id="txtarea" class="form-control" placeholder="Mô tả sản phẩm" name="desc" required></textarea>
199 </div>
200 </div>
201 </div>
202
203 <div class="row">
204
205 <div class="col-md-12">
206 <div class="form-group">
207 <label style="display: block; border-radius: 5px; letter-spacing: 2px; background: #fff; color: #333; padding: 10px; border: 1px solid #ccc; cursor: pointer; text-align: center; font-size: 15px; font-weight: bold;" for="file" class="file_lbl"><i style="font-weight: bold; font-size: 19px;" class="pe-7s-upload"></i>Chọn ảnh nổi bật<input type="file" style="display: none;" id="file" name="file" required /></label>
208 </div>
209 </div>
210
211 </div>
212
213 <input type="submit" name="submit" style="background: #FF5722; border: 1px solid #FF5722" value="Lưu" class="btn btn-info btn-fill pull-right" />
214 <div class="clearfix"></div>
215 </form>
216 </div>
217 </div>
218 </div>
219
220 </div>
221 </div>
222 </div>
223
224
225 <footer class="footer">
226 <div class="container-fluid">
227
228 <p class="copyright pull-right">
229 © <?php echo strftime("%Y", time())?> <a href="index.php">Unique Restaurant</a>
230 </p>
231 </div>
232 </footer>
233
234 </div>
235 </div>
236
237
238 </body>
239
240 <!-- Core JS Files -->
241 <script src="assets/js/jquery-1.10.2.js" type="text/javascript"></script>
242 <script src="assets/js/bootstrap.min.js" type="text/javascript"></script>
243
244 <!-- Checkbox, Radio & Switch Plugins -->
245 <script src="assets/js/bootstrap-checkbox-radio-switch.js"></script>
246
247 <!-- Charts Plugin -->
248 <script src="assets/js/chartist.min.js"></script>
249
250 <!-- Notifications Plugin -->
251 <script src="assets/js/bootstrap-notify.js"></script>
252
253 <!-- Google Maps Plugin -->
254
255 <!-- Light Bootstrap Table Core javascript and methods for Demo purpose -->
256 <script src="assets/js/light-bootstrap-dashboard.js"></script>
257
258 <!-- Light Bootstrap Table DEMO methods, don't include it in your project! -->
259 <script src="assets/js/demo.js"></script>
260
261 </html>